{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# ***Introduction to Radar Using Python and MATLAB***\n",
    "## Andy Harrison - Copyright (C) 2019 Artech House\n",
    "<br/>\n",
    "\n",
    "# Loop Gain\n",
    "***"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The radar loop gain is defined as (Equation 4.41)\n",
    "\n",
    "$$\n",
    "C = \\frac{r_0^4 \\,{SNR}_0}{\\sigma_0}  \\hspace{0.5in} \\text{(m}^2\\text{)}\n",
    "$$\n",
    "***"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Begin by getting the library path"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import lib_path"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Set the reference range, reference RCS, and reference SNR"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "reference_range = 10e3    # meters\n",
    "\n",
    "reference_rcs   = 10.0   # dBsm\n",
    "\n",
    "reference_snr   = 10.0   # dB"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Set up the keyword args"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "kwargs = {'reference_range': reference_range,\n",
    "\n",
    "          'reference_rcs': 10.0 ** (reference_rcs / 10.0),\n",
    "\n",
    "          'reference_snr': 10.0 ** (reference_snr / 10.0)}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Import the `loop_gain` routine"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "from Libs.radar_range import radar_range"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Calculate the loop gain"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "lg = radar_range.loop_gain(**kwargs)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Import the log10 function from `scipy` for displaying the loop gain in dBsm"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "160.00\n"
     ]
    }
   ],
   "source": [
    "from numpy import log10\n",
    "\n",
    "print('{:.2f}'.format(10.0 * log10(lg)))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
